/*
 * InvulgoTracker
 * Copyright (C) Thomas Andersen 2011 <thomas.1.andersen@gmail.com>
 * 
 * InvulgoTracker is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * InvulgoTracker is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along
 * with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _SUMMARY_VIEW_H_
#define _SUMMARY_VIEW_H_

#include <gtk/gtk.h>
#include "i-day-load.h"
#include "task-time.h"
#include "taskid.h"

class SummaryView : public IDayLoad
{
public:
    SummaryView();
    virtual ~SummaryView();
    void Clean();
    void Restart();
    void Init(GtkWidget *view, gboolean sortable = FALSE, gboolean showpct = FALSE);
    void CalcDay(guint year, guint month, guint day, gboolean accumulate = FALSE);
    void Data(gchar *name, gchar *timeStr, TaskId id);
    void AddToTask(TaskTime diff, gchar *taskName, TaskId id);
    bool GetFirst(gchar **name, gchar **timeStr);
    bool GetNext(gchar **name, gchar **timeStr);
    TaskId GetLastTaskId() { return lastTaskId; }
    TaskTime GetLastTime() { return lastTime; }
protected:

private:
    static gint sort_iter_compare_func_title(GtkTreeModel *model, GtkTreeIter  *a, GtkTreeIter  *b, gpointer userdata);
    static gint sort_iter_compare_func_time(GtkTreeModel *model, GtkTreeIter  *a, GtkTreeIter  *b, gpointer userdata);
    gint sort_iter_compare_func (GtkTreeModel *model, GtkTreeIter  *a, GtkTreeIter  *b, gpointer userdata);
    static void column_title_clicked(GtkTreeViewColumn *treeviewcolumn, gpointer user_data);
    static void column_time_clicked(GtkTreeViewColumn *treeviewcolumn, gpointer user_data);
    void CalcMonth(guint year, guint month);
    void CalcPct(glong type);
    enum
    {
        COL_TITLE = 0,
        COL_TIME,
        COL_ID,
        COL_TYPE,
        COL_VALUE,
        NUM_COLS
    };
    enum 
    {
        TYPE_NONE,
        TYPE_DAY_TITLE,
        TYPE_DAY,
        TYPE_DAYTOTAL,
        TYPE_DIVIDER,
        TYPE_MONTH_TITLE,
        TYPE_MONTH,
        TYPE_MONTHTOTAL,
        TYPE_YEAR
    };
    enum
    {
        SORT_TITLE = 0,
        SORT_TIME
    };

    GtkTreeModel *CreateModel();

    GtkTreeView *view;
    gboolean isSortable;
    gboolean isShowingPct;
    GtkTreeModel *model;
    TaskTime taskTime;
    TaskTime totalTime;
    TaskTime *prevTime;
    gchar *prevName;
    TaskId prevId;
    glong currentType;
    GtkTreeIter currentIter;
    TaskId lastTaskId;
    TaskTime lastTime;
    GtkTreeViewColumn *pctColumn;
};

#endif // _SUMMARY_VIEW_H_
